const { Service } = require("uni-cloud-router");
const { result_success, result_error } = require('http-result-modle');
const db = uniCloud.database();

module.exports = class ShopService extends (
    Service
) {

    async getShopInfoById(event) {
        let params;
        if(event.params){
            params = event.params;
        }else if(event.data){
            params = event.data;
        }else{
            return result_error('参数丢失', null);
        }

        if(!params){
            return result_error('参数丢失', null);
        }
        if(!params.shop_id){
            return result_error('门店主键丢失', null);
        }

        let shopInfoQuery = {
            _id: params.shop_id
        };

        let shopInfoResult = await db.collection('wmzmall-shop').where(shopInfoQuery).orderBy("create_time", "desc").limit(1).get();

        if(shopInfoResult && shopInfoResult.data && shopInfoResult.data.length > 0){
            return result_success(shopInfoResult.data[0], '根据id获取门店信息数据成功');
        }else{
            return result_error('根据id获取门店信息数据失败', null);
        }
    }

};
